function  [bdraw,m1,CC1]=drawnorm(y,x,prm,prprec,sig)
%function [bdraw,m1,CC1]=drawnorm(y,x,prm,prprec,sig) 
% Draw Coefficients from a Normal distribution when prior is also 
%      Normal( prm, prprec^(-1) )  and prprec is the precision
%      No restrictions imposed when sampling 
% 
% y      (Txn) 
% x      (TxK)  
% Prm    (Kx1)  Prior Mean 
% prprec (KxK)  Prior Precision
% sig    (1x1)  Variance of the errors
%
% bdraw  (1xK)  Draw from the posterior normal as a row vector 
% m1     (1xK)  Posterior mean 
% CC1    (KxK)  Cholelsky of the posterior variance 
%               V1= CC1'*CC1  

% Remove to run faster 
% [ty,ny]=size(y); 
% [tx,nx]=size(x); 
% if tx~=ty
%     error('Not equal number of observations in drawcoef'); 
% end; 

nk=length(prm);
V1=( prprec+ (1/sig)*(x'*x)  ) \ eye(nk) ;   % Posterior Variance  
m1=V1*(prprec*prm + (1/sig)*(x'*y) );        % Posterior Mean  
CC1=chol(V1); 
bdraw=m1'+ randn(1,nk)*CC1;
m1=m1'; 